package svc

import (
	"fmt"
	"zero-demo/user-api/internal/config"
	"zero-demo/user-api/model"

	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

type ServiceContext struct {
	Config        config.Config
	UserModel     model.UserModel
	UserDataModel model.UserDataModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	psqlcfg := c.Postgresql
	DataSource := fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=disable",
		psqlcfg.User,
		psqlcfg.Password,
		psqlcfg.Host,
		psqlcfg.Port,
		psqlcfg.Name,
	)
	fmt.Println(DataSource)
	conn := sqlx.NewSqlConn("postgres", DataSource)
	return &ServiceContext{
		Config:        c,
		UserModel:     model.NewUserModel(conn),
		UserDataModel: model.NewUserDataModel(conn),
	}
}
